// CryScaleform.cpp : Defines the exported functions for the DLL application.
//

#include "StdAfx.h"
#include "ScaleformGFx.h"

#include "Scaleform/FlashPlayerInstance.h"
#include "Scaleform/GAllocatorCryMem.h"

#include "GFxAmpServer.h"

bool CScaleformGFx::IsScaleformSupported() const
{
#ifndef EXCLUDE_SCALEFORM_SDK
	return true;
#endif
	return false;
}

void CScaleformGFx::Release()
{
#ifndef EXCLUDE_SCALEFORM_SDK
	CSharedFlashPlayerResources::Shutdown();
#endif
	delete this;
}

IFlashPlayer* CScaleformGFx::CreateFlashPlayerInstance() const
{
#ifndef EXCLUDE_SCALEFORM_SDK
	return new CFlashPlayer;
#else
	return 0;
#endif
}

IFlashPlayerBootStrapper* CScaleformGFx::CreateFlashPlayerBootStrapper() const
{
#ifndef EXCLUDE_SCALEFORM_SDK
	return CFlashPlayer::CreateNewBootStrapper();
#else
	return 0;
#endif
}

void CScaleformGFx::RenderFlashInfo()
{
#ifndef EXCLUDE_SCALEFORM_SDK
	CFlashPlayer::RenderFlashInfo();
#endif
}

void CScaleformGFx::GetFlashMemoryUsage(ICrySizer* pSizer)
{
#ifndef EXCLUDE_SCALEFORM_SDK
	CSharedFlashPlayerResources::GetAccess().GetMemoryUsage(pSizer);
#endif
}

void CScaleformGFx::SetFlashLoadMovieHandler(IFlashLoadMovieHandler* pHandler) const
{
#ifndef EXCLUDE_SCALEFORM_SDK
	CFlashPlayer::SetFlashLoadMovieHandler(pHandler);
#endif
}

void CScaleformGFx::GetFlashProfileResults(float& accumTime, bool /*reset*/) const
{
#ifndef EXCLUDE_SCALEFORM_SDK
	CFlashPlayer::GetFlashProfileResults(accumTime);
#else
	accumTime = -1.0f;
#endif
}

void CScaleformGFx::GetFlashRenderStats(unsigned & numDPs, unsigned int& numTris)
{
#if !defined(RELEASE)

	numDPs = 0;
	numTris = 0;

#ifndef EXCLUDE_SCALEFORM_SDK
	GRendererXRender* pFlashRenderer(CSharedFlashPlayerResources::GetAccess().GetRenderer(true));

	if (pFlashRenderer)
	{
		GRenderer::Stats stats;
		pFlashRenderer->GetRenderStats(&stats, false);

		numDPs = stats.Primitives;
		numTris = stats.Triangles;
	}
#endif

#endif
}

void CScaleformGFx::SetThreadIDs(uint32 mainThreadID, uint32 renderThreadID)
{
#ifndef EXCLUDE_SCALEFORM_SDK
	GRendererXRender* pRenderer = CSharedFlashPlayerResources::GetAccess().GetRenderer(true);
	if (pRenderer)
	{
		pRenderer->SetThreadIDs(mainThreadID, renderThreadID);
	}
#endif
}

void CScaleformGFx::AmpEnable(bool bEnable)
{
#ifndef EXCLUDE_SCALEFORM_SDK
#if defined(GFX_AMP_SERVER)
	GFxAmpServer::GetInstance().SetState(Amp_Disabled, !bEnable);
#endif
#endif
}


void CScaleformGFx::AmpAdvanceFrame()
{
#ifndef EXCLUDE_SCALEFORM_SDK
#if defined(GFX_AMP_SERVER)
	if (!(GFxAmpServer::GetInstance().GetCurrentState() & Amp_Disabled))
	{
		GFxAmpServer::GetInstance().AdvanceFrame();
	}
#endif
#endif
}

void CScaleformGFx::ResetFlashMeshCache() const
{
#ifndef EXCLUDE_SCALEFORM_SDK
	CSharedFlashPlayerResources::GetAccess().ResetMeshCache();
#endif
}



#include UNIQUE_VIRTUAL_WRAPPER(IScaleformGFx)

